package utils
{
	import data.Category;
	import flash.xml.XMLNode;
	
	/**
	 * ...
	 * @author Henrik Riise Hansen
	 */
	public class XMLparser
	{
		public function XMLparser()
		{
		}
		
		public static function parse(xml:XML):Array
		{
			var dat:Array = new Array;
			
			for each (var i:XML in xml.elements())
			{
				var name:String = i.localName();
				
				switch (name)
				{
					case "categories": 
					parseCategories(i);
					break;
					
					default:
					//parseMedia(i);
					break;
				}
			}
			
			
			return dat;
		}
		
		private static function parseCategories(xml:XML):Category
		{
			
			trace('name: ' + xml.name());
			
			for each (var att:XML in xml.attributes())
			{
				var category:Category = new Category;
				var attibuteName:String = att.name();
				
				switch (attibuteName)
				{
					case 'id': 
					break;
					
					case 'type': 
					break;
				    
				    case 'sortby':
					break;
					
				    case 'parentid':
					break;
					
					case 'name':
					
					break;
				}
				
				trace("Attribute: " + att.name() + " = " + att);
				
			}
			
			for each (var i:XML in xml)
			{
				
				if (i.children() == xml)
				{
					
					trace('value: ' + i.children());
					trace('......................');
				}
				else
				{
					for each (i in xml.children())
					{
						trace('this node has children: ');
						parseCategories(i);
					}
				}
			}
			
			return category;
		}
		
		private static function parseMedia(xml:XML):Array
		{
			var data:Array = new Array;
			
			for each (var i:XML in xml)
			{
				
			}
			
			return data;
		}
	
	}

}